//
//  PosNewsController.m
//  PosApp
//
//  Created by 刘萍 on 2018/9/10.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "PosNewsController.h"
#import "PosNewsView.h"
#import "PosModel.h"

#import "LingQuPosController.h"

@interface PosNewsController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *NewsScrollView;
@property (strong, nonatomic) PosNewsView * NewsView;
@property (strong, nonatomic) PosModel * posmodel;
@property (assign, nonatomic) NSUInteger ImageH;
@property (strong, nonatomic) MBProgressHUD * hud;

@end

@implementation PosNewsController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationItem.title = @"确定领取";
    self.NewsView = [[NSBundle mainBundle] loadNibNamed:@"PosNewsView" owner:self options:nil][0];
    self.NewsView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 340);
    [self.NewsView CreatePosNewsView];
    
    [self.NewsScrollView addSubview:self.NewsView];
    self.NewsScrollView.contentSize = CGSizeMake(0, CGRectGetMaxY(self.NewsView.frame));
    [self UpDataOfPosNewsController];
    
}

- (void)UpDataOfPosNewsController{
    self.hud = [MainObjectWay CreateHUDView:self.view];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:self.PosID forKey:@"pos_id"];
    
    [MainObjectWay PostWithMethod:@"pos_detail" andAction:@"Pos" andAddParam:YES parameters:dic success:^(id responseObject) {
        NSLog(@"请求的POS信息 = %@",responseObject);
        
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            NSMutableDictionary * dic = responseObject[@"data"];
            PosModel * model = [PosModel mj_objectWithKeyValues:dic];
            NSLog(@"%@",model);
            self.posmodel = model;
            [self.NewsView setModel:model];
            [self.hud hideAnimated:YES];
            self.ImageH = 340;
            NSMutableArray * arr = [NSMutableArray arrayWithArray:model.pos_description];
            for (int i = 0;  i < arr.count; i ++) {
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:arr[i]]];
                UIImage *showimage = [UIImage imageWithData:data];
                NSLog(@"w = %f,h = %f",showimage.size.width,showimage.size.height);
                CGFloat scale = showimage.size.height/showimage.size.width;
                
                UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.ImageH, KScreenW, KScreenW*scale)];
                imageV.image = showimage;
                
                [self.NewsScrollView addSubview:imageV];
                self.NewsScrollView.contentSize = CGSizeMake(0, CGRectGetMaxY(self.NewsView.frame)+self.ImageH);
                self.ImageH = self.ImageH + KScreenW*scale;
                
            }
            
            
        }else{
            [self.hud hideAnimated:YES];
        }
    } failure:^(NSError *error) {
        [self.hud hideAnimated:YES];
        NSLog(@"错误信息 = %@",error);
    }];
}

- (IBAction)ClickOnBtnToLingQuPosJi:(id)sender {
    
    LingQuPosController * LingQuC = [[LingQuPosController alloc] init];
    LingQuC.Model = self.posmodel;
    [self.navigationController pushViewController:LingQuC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
